import 'dart:convert' show json;

import 'package:freedom/util/data_type.dart';

class MahjongUserSwapCard {
  MahjongUserSwapCard({
    this.inSwapCard,
    this.outSwapCard,
  });

  factory MahjongUserSwapCard.fromJson(Map<String, dynamic>? jsonRes) {
    if (jsonRes == null) {
      return MahjongUserSwapCard();
    }
    return MahjongUserSwapCard(
      inSwapCard:
          SwapCard.fromJson(asT<Map<String, dynamic>>(jsonRes['inSwapCard'])),
      outSwapCard:
          SwapCard.fromJson(asT<Map<String, dynamic>>(jsonRes['outSwapCard'])),
    );
  }

  SwapCard? inSwapCard;
  SwapCard? outSwapCard;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'inSwapCard': inSwapCard,
        'outSwapCard': outSwapCard,
      };

  @override
  String toString() {
    return json.encode(this);
  }
}

class SwapCard {
  SwapCard({
    this.userId,
    this.cards,
  });

  factory SwapCard.fromJson(Map<String, dynamic>? jsonRes) {
    if (jsonRes == null) {
      return SwapCard();
    }
    final List<int>? cards = jsonRes['cards'] is List ? <int>[] : null;
    if (cards != null) {
      for (final dynamic item in jsonRes['cards']) {
        if (item != null) {
          cards.add(asT<int>(item)!);
        }
      }
    }

    return SwapCard(
      userId: asT<String>(jsonRes['userId']),
      cards: cards,
    );
  }

  String? userId;
  List<int>? cards;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'userId': userId,
        'cards': cards,
      };

  @override
  String toString() {
    return json.encode(this);
  }
}
